﻿using AutoMapper;
using J.Model;
using J.ProductSet.Application.Command.ClassifiedManagementCommand;
using MediatR;
using SqlSugar;

namespace J.ProductSet.Application.CommandHandler.ClassifiedManagementCommandHandler
{
    public class ClassifiedManagementPostCommandHandler : IRequestHandler<ClassifiedManagementPostCommand, int>
    {
        private readonly ISqlSugarClient _sqlSugarClient;
        public IMapper _mapper;
        public ClassifiedManagementPostCommandHandler(ISqlSugarClient sqlSugarClient, IMapper mapper)
        {
            _sqlSugarClient = sqlSugarClient;
            _mapper = mapper;
        }
        public async Task<int> Handle(ClassifiedManagementPostCommand request, CancellationToken cancellationToken)
        {
            ClassifiedManagement modes = _mapper.Map<ClassifiedManagement>(request);
            modes.CreationTime = DateTime.Now;
            return await _sqlSugarClient.Insertable(modes).ExecuteCommandAsync();
        }
    }
}
